breed

 

breed is a special primitive that can only be placed in the top of a netlogo file that defines a particular kind or breed of turtle. breed is useful when you have different classes of turtles that each need to have their own behavior, and you want to have an easy way to reference each group within your code. To create a breed, you call breed with two names, first the plural name (dogs, cats, mice) and then the singular (dog, cat, mouse). So if we were to create a breed for wolves, we would say breed [wolves wolf].

breed is also special in that it creates other commands that can be used later on in your code. For example, whereas to create a generic turtle, you use create-turtles, once you define a breed, say, for instance, dogs, using breed [dogs dog] you create those dogs using create-dogs, check if there are any dogs here using dogs-here instead of turtles-here, and if you want to talk to the 0th dog, you use dog 0 instead of turtle 0. Any time you see <breed> or <breeds> in the dictionary, you can substitute in the singular or plural name for your newly created breed, respectively.

In this example, I use breed to create two classes of turtles with very different behavior, trees and lumberjacks. Trees just sit there, and lumberjacks wander around and, if they happen upon a patch with a tree, cut it down. While it wouldn't be too difficult to create a version of this model without breed using the with command, breed allows us to write much more readable code.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

Once you mastered the breed primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Similar primitives:
create-turtles

creates turtles with random colors and headings in the default shape of a turtle

Read more
turtles-own

Declare a variable that belongs to turtles.

Read more
die

Remove a turtle or link from the world.

Read more
ask

a reporter that is used to make the agents in the agentset do something.

Read more
 
Learn another primitive